package com.wisemoresystem.seal.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.ne.framework.data.page.Page;
import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wisemoresystem.seal.base.service.BaseService;

/**
 * 签到签退
 * 
 * @author Administrator
 *
 */
@Service
public class MarkLogService extends BaseService {

	@Autowired
	private BankService service;

	public List<Map<String, Object>> selectMarkLogList(String srh_name,
			String bank, String srh_start, Page page) {
		String ids = service.selectUbank2();
		if (ChkTools.isNull(ids)) {
			ids = "''";
		}
		try {
			String sql = "select t.*,tb.name from @t_log t "
					+ " left outer join t_user tu on t.user_id=tu._id and tu.status=0 "
					+ " left outer join t_bank tb on tb._id=tu.bank_id and tb.status=0 "
					+ " where t.status=0 and t.level_msg='中' and tb._id in (@ids)"
					+ " and t.log like ? and tb.name like ? order by t.created desc";
			if (ChkTools.isNull(srh_start)) {
				sql = sql.replace("@t_log", "t_log");
			} else {
				sql = sql.replace("@t_log", "t_log_" + srh_start);
			}
			List<String> params = new ArrayList<String>();
			if (ChkTools.isNull(srh_name)) {
				sql = sql.replace("and t.log like ?", "");
			} else {
				params.add("%" + srh_name + "%");
			}
			if (ChkTools.isNull(bank)) {
				sql = sql.replace("and tb.name like ?", "");
			} else {
				params.add("%" + bank + "%");
			}
			sql = sql.replace("@ids", ids);
			List<Map<String, Object>> list = jc.queryForList(sql,
					params.toArray(), page);
			return list;
		} catch (Exception e) {
			return null;
		}
	}
}
